//
//  ComposePhotosView.m
//  CC
//
//  Created by Calvin on 5/20/15.
//  Copyright (c) 2015 Calvin. All rights reserved.
//

#import "ComposePhotosView.h"
#import "CustomTextView.h"

@interface ComposePhotosView()<CustomTextViewDelegate>

@end

@implementation ComposePhotosView
-(void)addImage:(UIImage *)image
{
    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.contentMode = UIViewContentModeScaleToFill;
    imageView.image=image;
    [self addSubview:imageView];
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    NSInteger count = self.subviews.count;
    int maxColsPerRow = 4;
    CGFloat margin = 10;
    CGFloat imageViewW = (self.bounds.size.width - (maxColsPerRow + 1) * margin)/maxColsPerRow;
    CGFloat imageViewH = imageViewW;
    for (int i = 0 ; i < count; i++) {
        int row = i % maxColsPerRow;
        int col = i / maxColsPerRow;
        UIImageView *imageView = self.subviews[i];
        CGFloat w = imageViewW;
        CGFloat h = imageViewH;
        CGFloat x = row * (imageViewH + margin);
        CGFloat y = col * (imageViewW + margin) + margin;
        imageView.frame = CGRectMake(x, y, w, h);
    }
}

-(void)changeComposePhotoViewHeight:(CGFloat)height
{
    NSLog(@"1");
}

-(NSArray *)images
{
    NSMutableArray *images = [NSMutableArray array];
    for (UIImageView *imageView in self.subviews) {
        [images addObject:imageView.image];
    }
    
    return images;
}
@end
